package com.contract.commonlib.webview;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import com.tencent.smtt.export.external.interfaces.SslError;
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

/**
 * Created by Ace on 2018/5/11.
 */

public class MyWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith("wtai://wp/mc;")) {//http://wpa.qq.com/msgrd?v=3&uin=1536257130&site=oicqzone.com&menu=yes
            try {//mqqwpa://im/chat?chat_type=wpa&uin=1536257130&version=1&src_type=web&web_src=null
                String replace = url.replace("wtai://wp/mc;", "tel:");
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(replace));
                view.getContext().startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (url.startsWith("mqqwpa") || url.startsWith("tencent://")
                || url.startsWith("mailto") || url.startsWith("http://wapp.baidu.com") || url.startsWith("bubblenews://")) {
            try {
                if (!TextUtils.equals(url, "bubblenews://splash")) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    view.getContext().startActivity(intent);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (url.contains("www.doudou.com/?index")) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
        } else if (url.startsWith("tbfrs://")) {//百度贴吧
        } else if (url.startsWith("wvjbscheme://")) {
        } else if (url.startsWith("http:") || url.startsWith("https:")) {
            view.loadUrl(url);
        }
        return true;
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }
}
